package com.cskaoyan.controller;

import com.cskaoyan.bean.pojo.User;
import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.service.UserService;
import com.cskaoyan.service.userserviceimpl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: lds
 * @clsss: UserController
 * @description:
 */
@SuppressWarnings("all")
@RestController
public class UserController {

    @Autowired
    UserServiceImpl userServiceImpl;

    /**
     * @param user
     * @return BaseRespVo
     * @description:验证用户是否存在
     */
    @Autowired
    UserService userService;

    @RequestMapping(value = "user7/login", method = RequestMethod.POST)
    public BaseRespVo login7(User user) {
        Integer integer = userService.checkUser(user);
        if (integer == 404) {
            return BaseRespVo.fail("查询异常");
        }
        if (integer == 1) {
            return BaseRespVo.ok();
        } else {
            return BaseRespVo.fail("没有此用户");
        }

    }


    @RequestMapping("query/{id}")
    public BaseRespVo queryUserById(@PathVariable("id") Integer id) {
        System.out.println(id);
        User user = userServiceImpl.selectUser(new User(id, null, null));
        return BaseRespVo.ok(user);
    }

    /**
     * @param id
     * @return
     * @descrption:根据参数id查询user信息
     */
    @RequestMapping("user888/queryOne")
    public BaseRespVo queryOne(Integer id) {
        User user = userService.queryOneUser(id);
        return BaseRespVo.ok(user);
    }

    @RequestMapping("/user666/query/{id}")
    public BaseRespVo query666(@PathVariable("id") int id) {
        User user = userService.query666ById(id);
        if (user == null) {
            return BaseRespVo.fail("没有符合条件的用户信息");
        }
        return BaseRespVo.ok(user);
    }


    @RequestMapping("search/{id}")
    public BaseRespVo queryUser(@PathVariable("id") Integer id) {
        User user = userService.selectUserById(id);
        return BaseRespVo.ok(user);
    }

    @RequestMapping("user/yfs")
    public BaseRespVo addUserYfs(User user){

    Integer count= userService.addUserYfs(user);

        return BaseRespVo.ok();
    }

    @RequestMapping("user/delete/{id}")
    public BaseRespVo addUserYfs(@PathVariable("id") Integer id){

        userService.deleteUserById(id);
        return BaseRespVo.ok();
    }


}
